<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
		<title>
			后台登录
		</title>
	</head>
	<body>
		<div class="adminLogin">
		<h1>
			后台登录
		</h1>
		<form>
			<label>用户名：
			<input type="text" class="username">
			</label>
			<br/>
			<label>密码：
			<input type="password" class="password">
			</label>
			<br/>
			<input type="button" value="登录" class="loginButton">
		</form>
		</div>
	</body>
	<script src="../ajax.js"></script>
	<script>
		function $(el){
			return document.querySelector(el)
		}
		var loginButton = $('.loginButton')
		
		loginButton.onclick = function(){
		var username = $('.username').value
		var password = $('.password').value
		console.log(username)
		ajax({
			url:'http://localhost:3000/adminLogin',
			type:'POST',
			async:true,
			data:{
				username,
				password
			},
			success:function(data){
				console.log(data)
				var dataJson = JSON.parse(data)
				if(dataJson.status == 200 ){
					document.cookie = "token="+dataJson.token
					console.log(document.cookie)
					window.location.href = './index.html'
				}else{
						alert('密码错误')
				}
			}
			})
		}
	</script>
</html>
